import os

path_of_current_file = os.path.abspath(__file__)
path_of_current_dir = os.path.split(path_of_current_file)[0]

chdir = path_of_current_dir

# # 开启预加载模式
# preload_app = True

# # 并行工作进程数
workers = 2

# # 指定每个工作者的线程数
threads = 4

# 监听内网端口5000
bind = '0.0.0.0:12222'

# 工作模式协程
worker_class = 'gthread'

logconfig_dict = dict(
    disable_existing_loggers=True,
    loggers={
        "gunicorn.error": {
            "handlers": ["error"],
            "propagate": False,
            "qualname": "gunicorn.error"
        },
        "peewee": {
            "handlers": ["access", ],
            "propagate": False,
            "qualname": "peewee"
        },
        "app": {
            "handlers": ["access"],
            "propagate": False,
            "qualname": "app"
        },
    },
    handlers={
        "error": {
            "class": "logging.handlers.RotatingFileHandler",
            "maxBytes": 1024 * 1024 * 50,  # 打日志的大小，200M
            "backupCount": 1,  # 备份多少份，经过测试，最少也要写1，不然控制不住大小
            "formatter": "generic",  # 对应下面的键
            'mode': 'w+',
            "filename": "./log/error.log"  # 打日志的路径
        },
        "console": {
            "class": "logging.StreamHandler",
            "formatter": "generic",
            "stream": "ext://sys.stdout"
        },
        "access": {
            "class": "logging.handlers.RotatingFileHandler",
            "maxBytes": 1024 * 1024 * 200,  # 打日志的大小，200M
            "backupCount": 1,  # 备份多少份，经过测试，最少也要写1，不然控制不住大小
            "formatter": "generic",  # 对应下面的键
            'mode': 'w+',
            "filename": "./log/access.log"  # 打日志的路径
        }
    },
    formatters={
        "generic": {
            "format": '%(asctime)s - %(name)s - "%(pathname)s:%(lineno)d" - %(funcName)s - %(levelname)s - %(message)s',
            "datefmt": "%Y-%m-%d %H:%M:%S",
            "class": "logging.Formatter"
        }
    }
)
